<?php
require_once './class/Login.inc';

$eid = $_POST ['eid'];
$passwd = $_POST ['passwd'];

$login = new Login ( $eid, $passwd );

if ($login->getSession () == null) {
	if ($login->confirmInfo ( $eid, $passwd )) {
		$login->setSession ( $eid, $passwd );
		$login->setSessionTime ();
		$login->checkDailyWorkCondition ();
	}
}
$curTime = time ();
$loginTime = $login->getSessionTime ();
if ($curTime - $loginTime >= (60 * 20)) {
	$login->destroySession ();
	echo "<script type='text/javascript'>";
	echo "alert('로그인 후 대기 시간이 넘어 로그아웃 되었습니다. 다시 로그인 해주세요.');";
	echo "parent.window.location.replace('".Login::CONST_HOME."');";
	echo "</script>";
} else {
	$login->updateSessionTime ();
}
?>
<link href="./css/header.css" rel="stylesheet">

<div class="modal fade" id="logoutModal" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">

			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel">로그아웃</h4>
			</div>
			<div class="modal-body">
				로그아웃 하시겠습니까?<br>저장하지 않은 정보는 사라집니다.
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default btn-logout"
					data-dismiss="modal">아니오</button>
				<button type="button" class="btn btn-primary btn-logout"
					data-dismiss="modal" onclick="logout();">예</button>
			</div>
		</div>
		<!-- /.modal-content -->
	</div>
	<!-- /.modal-dialog -->
</div>
<!-- /.modal -->
<script>
	function logout() {
		<?php
		echo "parent.window.location.replace('".Login::CONST_HOME."');";
		?>
	}
</script>
<!-- Fixed navbar -->
<div class="navbar navbar-default navbar-static-top" role="navigation">
	<div class="container">
		<div class="navbar-header">
			<button type="button" class="navbar-toggle" data-toggle="collapse"
				data-target=".navbar-collapse">
				<span class="sr-only">Toggle navigation</span> <span
					class="icon-bar"></span> <span class="icon-bar"></span> <span
					class="icon-bar"></span>
			</button>
			<a class="navbar-brand" href="./main.php">코리아넷운수</a>
		</div>
		<div class="navbar-collapse collapse">
			<ul class="nav navbar-nav">
			<?php
			$src = basename ( $_SERVER ['PHP_SELF'] );
			switch ($login->getGrade ()) {
				case 1 : // 최고관리자
				case 2 : // 일반관리자
					if (strnatcasecmp ( $src, "employee_management.php" ) == 0 || strnatcasecmp ( $src, "daily_report.php" ) == 0) {
						echo "<li class='active'>";
					} else {
						echo "<li>";
					}
					echo "<a href='./employee_management.php'>인력 관리</a></li>";
					echo "<li><a href='#'>재고 관리</a></li>";
					echo "<li><a href='#'>차량 관리</a></li>";
					echo "<li><a href='#'>배차 업무</a></li>";
					break;
				case 4 : // 회원
					if (strnatcasecmp ( $src, "payslip.php" ) == 0) {
						echo "<li class='active'>";
					} else {
						echo "<li>";
					}
					echo "<a href='./payslip.php?id=" . $login->getSession () . "'>운송료 조회</a></li>";
					break;
				case 3 : // 업체
					echo "</li><li><a href='#'>배차 요청</a></li>";
					break;
			}
			
			?>
			<!-- <li class='active'> 자기 자신일 경우 -->
			</ul>
			<ul class="nav navbar-nav navbar-right">
				<?php
				if ($login->getGrade () == 1 || $login->getGrade () == 2) {
					echo "<li id='admin1'><a href='./admin.php'><button type='button' class='btn btn-warning'>관리자</button></a></li>";
				}
				?>
				<li><a href="./qna.php"><button type="button"
							class="btn btn-primary">문의하기</button></a></li>
				<?php
				if ($login->getGrade () != 4) {
					echo "<li><a href='./document.php'><button type='button' class='btn btn-primary'>문서자료실</button></a></li>";
				}
				if ($login->getGrade () != 1) {
					echo "<li><a href='./employee_detail.php?pageType=3&id=" . $login->getSession () . "'><button type='button' class='btn btn-info
					'>내 정보</button></a></li>";
				}
				?>
				<li><a href="#"><button type="button" class="btn btn-danger"
							data-toggle="modal" data-target="#logoutModal">로그아웃</button></a></li>
			</ul>
		</div>
		<!--/.nav-collapse -->
	</div>
</div>